package com.itheima.controller;

import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clazzs")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;


    /**
     * 班级列表查询（分页查询）dasdsadasd吱吱吱2222
     *
     * @param clazzQueryParam
     * @return
     */
    @GetMapping
    public Result pageQuery(ClazzQueryParam clazzQueryParam) {
        PageResult<Clazz> pageInfo = clazzService.pageQuery(clazzQueryParam);
        return Result.success(pageInfo);
    }


    /**
     * 删除班级
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        clazzService.delete(id);
        return Result.success();
    }


    /**
     * 添加班级
     *
     * @param clazz
     */
    @PostMapping
    public Result add(@RequestBody Clazz clazz) {
        clazzService.add(clazz);
        return Result.success();
    }


    /**
     * 根据班级id查询班级
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getByClazzId(@PathVariable Integer id) {
        Clazz clazz = clazzService.getByClazzId(id);
        return Result.success(clazz);
    }


    /**
     * 修改班级
     *
     * @param clazz
     * @return
     */
    @PutMapping
    public Result update(@RequestBody Clazz clazz) {
        clazzService.update(clazz);
        return Result.success();
    }


    /**
     * 查询所有班级
     *
     * @return
     */
    @GetMapping("/list")
    public Result list() {
        List<Clazz> clazzList = clazzService.list();
        return Result.success(clazzList);
    }
}
